package com.ruoyi.web.controller.cert;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cert.domain.CertOrganization;
import com.ruoyi.cert.service.ICertOrganizationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 颁发机构Controller
 *
 * @author mxh
 * @date 2023-03-26
 */
@Api("颁发机构")
@RestController
@RequestMapping("/cert/certOrganization")
public class CertOrganizationController extends BaseController {
    @Autowired
    private ICertOrganizationService certOrganizationService;

    /**
     * 查询颁发机构列表
     */
    @PreAuthorize("@ss.hasPermi('cert:certOrganization:list')")
    @GetMapping("/list")
    @ApiOperation("查询颁发机构列表")
    public TableDataInfo list(CertOrganization certOrganization) {
        certOrganization.setDeptId(getDeptId());
        startPage();
        List<CertOrganization> list = certOrganizationService.selectCertOrganizationList(certOrganization);
        return getDataTable(list);
    }

    /**
     * 导出颁发机构列表
     */
    @PreAuthorize("@ss.hasPermi('cert:certOrganization:export')")
    @Log(title = "颁发机构", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CertOrganization certOrganization) {
        certOrganization.setDeptId(getDeptId());
        List<CertOrganization> list = certOrganizationService.selectCertOrganizationList(certOrganization);
        ExcelUtil<CertOrganization> util = new ExcelUtil<CertOrganization>(CertOrganization. class);
        util.exportExcel(response, list, "颁发机构数据");
    }

    /**
     * 获取颁发机构详细信息
     */
    @PreAuthorize("@ss.hasPermi('cert:certOrganization:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取颁发机构详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(certOrganizationService.selectCertOrganizationById(id));
    }

    /**
     * 新增颁发机构
     */
    @PreAuthorize("@ss.hasPermi('cert:certOrganization:add')")
    @Log(title = "颁发机构", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增颁发机构")
    public AjaxResult add(@RequestBody CertOrganization certOrganization) {
        certOrganization.setDeptId(getDeptId());
        return toAjax(certOrganizationService.insertCertOrganization(certOrganization));
    }

    /**
     * 修改颁发机构
     */
    @PreAuthorize("@ss.hasPermi('cert:certOrganization:edit')")
    @Log(title = "颁发机构", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改颁发机构")
    public AjaxResult edit(@RequestBody CertOrganization certOrganization) {
        certOrganization.setDeptId(getDeptId());
        return toAjax(certOrganizationService.updateCertOrganization(certOrganization));
    }

    /**
     * 删除颁发机构
     */
    @PreAuthorize("@ss.hasPermi('cert:certOrganization:remove')")
    @Log(title = "颁发机构", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除颁发机构")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(certOrganizationService.deleteCertOrganizationByIds(ids));
    }
}
